package controllers


import (
	"github.com/astaxie/beego"
	"fmt"
	m"xmy/models/admin"
	"strconv"

)

type ConsultController struct {
	beego.Controller
}
//返回值 封装为 JSON 格式
func (this *ConsultController) Rsp(status bool, str string) {
	this.Data["json"] = &map[string]interface{}{"status": status, "info": str}
	this.ServeJSON()
}

func (c *ConsultController)  ConsultManage() {
	fmt.Println("进来--咨询管理--控制器啦！")
	c.TplName = "contact/consultManage.html"


}

func (this *ConsultController)  ConsultManagePage() {
	fmt.Println("进来--咨询列表--控制器啦！")
	page, _ := this.GetInt64("page")
	fmt.Println("page:", page)
	page_size, _ := this.GetInt64("rows")
	fmt.Println("page_size:", page_size)
	sort := this.GetString("sort")
	fmt.Println("sort:", sort)
	order := this.GetString("order")
	fmt.Println("order:", order)
	if len(order) > 0 {
		if order == "desc" {
			sort = "-" + sort
		}
	} else {
		sort = "Id"
	}
	nodes, count := m.GetConsultlist(page, page_size, sort)
	this.Data["json"] = &map[string]interface{}{"total": count, "rows": &nodes}
	fmt.Println(this.Data["json"])
	this.ServeJSON()
	return

}

func (c *ConsultController)  ConsultDetail() {
	fmt.Println("进来--咨询详情--控制器啦！")
	Id := c.GetString("Id")
	Consult_id, _ := strconv.ParseInt(Id, 10, 64)
	consult:= m.QueryConsult(Consult_id)
	fmt.Println("..............................",consult)
	c.Data["json"] = &map[string]interface{}{"rows": &consult}
	c.ServeJSON()
	return
}

func (c *ConsultController)  ConsultReplyContent() {
	fmt.Println("进来--咨询回复--控制器啦！")
	Replycontent := c.GetString("Replycontent")
	Id := c.GetString("Id")
	Consult_id, _ := strconv.ParseInt(Id, 10, 64)
	id,err:= m.UpdateConsult(Replycontent,Consult_id)
	if err == nil && id > 0 {
		c.Rsp(true, "1")
		return
	} else {
		c.Rsp(true, "0")
		return
	}
	return
}



